<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="12">
            <a-form-model-item
                label="姓名"
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
                prop="empId">
                <select-user-by-dep @back="changeVal"  :multi="multipleChoice" v-model="model.empId" :disabled="formDisabled"/>
              </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item
                label="部门"
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
                prop="deptId">
                <j-select-depart disabled v-model="model.deptId"/>
              </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item
                label="所属团队"
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
                prop="teamId">
                <select-team-input
                  :disabled="formDisabled"
                  v-model="model.teamId"
                  :tdlx="1"
                />
              </a-form-model-item>
          </a-col>
          <!-- <a-col :span="12">
            <a-input-number
            disabled
            :max="99999999"
            :min="0"
            :precision="2"
            v-model="model.signatureFee"
            placeholder="请输入"
            style="width: 100%"
          />
          </a-col> -->
          <!-- 流程中的判断字段start -->
          <!-- 第二个审批节点的项目专员 -->
          
          <!-- <a-col :span="12">
            <a-form-model-item
              label="预计审核费(元)"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="approvalEngineer">
              <a-input-number
                :disabled="formDisabled"
                :max="99999999"
                :min="0"
                :precision="2"
                v-model="model.approvalEngineer"
                placeholder="请输入预计审核费"
                style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item
              label="扣除比例"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="projectSource">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="list"
                v-model="model.projectSource"
                dictCode="xmly_type"
                placeholder="请选择扣除比例"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item
              label="实际审核费(元)"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="approvalEngineer">
              <a-input-number
                disabled
                :max="99999999"
                :min="0"
                :precision="2"
                v-model="model.approvalEngineer"
                placeholder="请输入实际审核费"
                style="width: 100%"/>
            </a-form-model-item>
          </a-col> -->
          <!-- 流程中的判断字段end -->
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { getAction } from '@/api/manage'
  import SelectProjectInput from '@/views/scy/components/SelectProjectInput'
  import SelectMaterialInput from '@/views/scy/components/SelectMaterialInput'
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
  import SelectTeamInput from '@views/scy/components/SelectTeamInput';
  export default {
    name: 'ErpFirstInstanceEngineerForm',
    components: {
      SelectProjectInput,
      SelectMaterialInput,
      SelectUserByDep, // 人员选择
      SelectTeamInput // 团队选择
    },
    props: {
      // 表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      },
      multipleChoice:{
        type:Boolean,
        required: false,
        default:false
      }
    },
    data () {
      return {
        flag: false,
        model: {
         },
        labelCol: {
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 24 }
        },
        confirmLoading: false,
        validatorRules: {
          empId: [
              { required: true, message: '请选择人员!'}
          ],
          teamId: [
              { required: true, message: '请选择团队!' }
          ]
        }
      }
    },
    computed: {
      formDisabled() {
        return this.disabled
      }
    },
    created () {
       // 备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      changeVal(val){
        if(val){
          this.$set(this.model,'deptId',val[0].departId)
          this.$set(this.model,'empNo',val[0].workNo)
          console.log(this.model,'this.model');
          
          // this.$forceUpdate()
        }

         console.log(val,'val---');
         
      },
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.$refs['form'].clearValidate();
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.$emit('ok', this.model, this.flag);
          }
        })
      }
    }
  }
</script>
